import parseAmount from './parseAmount';

describe('parseAmount', () => {
  test.each`
    amount                     | decimalPlaces | expected
    ${'123.456'}               | ${undefined}  | ${'123'}
    ${'123.456'}               | ${3}          | ${'123.456'}
    ${'123.456'}               | ${2}          | ${'123.45'}
    ${'123.456'}               | ${1}          | ${'123.4'}
    ${'123.456'}               | ${0}          | ${'123'}
    ${'000123.456'}            | ${undefined}  | ${'123'}
    ${'000123.456'}            | ${3}          | ${'123.456'}
    ${'00123.456'}             | ${2}          | ${'123.45'}
    ${'00123.456'}             | ${1}          | ${'123.4'}
    ${'00123.456'}             | ${0}          | ${'123'}
    ${'000123.456000'}         | ${undefined}  | ${'123'}
    ${'000123.45600'}          | ${3}          | ${'123.456'}
    ${'00123.4560'}            | ${2}          | ${'123.45'}
    ${'00123.4560'}            | ${1}          | ${'123.4'}
    ${'00123.4560'}            | ${0}          | ${'123'}
    ${'.456'}                  | ${undefined}  | ${'0'}
    ${'0.456'}                 | ${3}          | ${'0.456'}
    ${'00.456'}                | ${2}          | ${'0.45'}
    ${'000.456'}               | ${1}          | ${'0.4'}
    ${'0000.456'}              | ${0}          | ${'0'}
    ${'123456'}                | ${undefined}  | ${'123456'}
    ${'123456'}                | ${3}          | ${'123456'}
    ${'123456'}                | ${2}          | ${'123456'}
    ${'123456'}                | ${1}          | ${'123456'}
    ${'123456'}                | ${0}          | ${'123456'}
    ${'000123456'}             | ${undefined}  | ${'123456'}
    ${'000123456'}             | ${3}          | ${'123456'}
    ${'00123456'}              | ${2}          | ${'123456'}
    ${'0123456'}               | ${1}          | ${'123456'}
    ${'0000123456'}            | ${0}          | ${'123456'}
    ${'12.012345678912345678'} | ${18}         | ${'12.012345678912345678'}
    ${'12.012345678912345678'} | ${17}         | ${'12.01234567891234567'}
    ${'asdas'}                 | ${3}          | ${undefined}
    ${'0.0.0'}                 | ${undefined}  | ${undefined}
    ${'-10.0'}                 | ${undefined}  | ${undefined}
    ${'6e-7'}                  | ${7}          | ${undefined}
  `(
    'parseAmount("$amount", $decimalPlaces) returns "$expected"',
    ({ amount, decimalPlaces, expected }) => {
      const result = parseAmount(amount, decimalPlaces);
      expect(result).toEqual(expected);
    },
  );
});
